﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace SPContrib.Extensions
{
    /// <summary>
    /// Extensions for the Assembly class
    /// </summary>
    public static class AssemblyExtensions
    {

        /// <summary>
        /// Finds attributes of a certain type
        /// </summary>
        /// <typeparam name="T">the type of attribute to locate</typeparam>
        public static IEnumerable<T> FindAttributes<T>(this Assembly instance)
            where T : Attribute
        {
            var customattributes = Attribute.GetCustomAttributes(instance, typeof(T), false);

            if (customattributes != null)
            {
                foreach (T attribute in customattributes)
                {
                    yield return attribute;
                }
            }
        }
    }
}
